package com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Controller
public class UploadController {

    @RequestMapping("/upload.do")
    public String shangchuan(@RequestParam("pic") MultipartFile pic){
        String fname = pic.getOriginalFilename();
        File ss = new File("d:/upload");
        if (!ss.exists()){
            ss.mkdirs();
        }
        System.out.println(fname);
        File f = new File("d:/upload/"+fname);
        try {
            pic.transferTo(f);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "/success";
    }
}
